// pages/operat/fleedTools/ .js
const LApp = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
  outInfo:{},
  myDate: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var outInfo = {};
    if (options.code != undefined) {
      let code = [options.code];
      if (code) {
       outInfo.Codes = code;
       outInfo.Num = code.length;
       outInfo.ProductID = options.ProductId
      }
    } else {
      outInfo.Codes = null;
      outInfo.Num = 0;
      outInfo.ProductID=0
    }
    this.setData({
      outInfo: outInfo
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var pages = getCurrentPages();
    var currPage = pages[pages.length - 1];
    if (this.data.myDate == 1) {
      this.setData({
        outInfo: {}
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  //click 继续扫码
  continueOper:function()
  {
   let that=this;
    wx.scanCode({
      success: (res) => {
        var codes = that.data.outInfo.Codes;
        if (codes){
          if (codes.indexOf(res.result) > -1) {
            wx.showToast({
              title: "该码已重复扫描",
            })
            return
          }
        }
        if (!that.data.outInfo.ProductID) that.data.outInfo.ProductID=0;
        LApp._get({
          url: 'nbapi/fleedtool/isoutstorage',
          data: { code: res.result, userId: LApp.globalData.userInfo.UserID,proId:that.data.outInfo.ProductID},
          success: function (r) {
           if(r){
             if (codes == null) codes = [];
             codes.push(res.result);
             var outInfo={};
            outInfo.Codes = codes;
            outInfo.Num =outInfo.Codes.length;
            outInfo.ProductID = r.ProductId;
            that.setData({
              outInfo: outInfo
            })
           }
           else{
             wx.showToast({
               title: r,
             })
           }
          }
        })
      
      }
    })
  },
  relationInfo: function () {
    let _this = this;
   // _this.data.outInfo.FormCode = "CK" + new Date().getTime();
        //页面传值并跳转
        if (_this.data.outInfo) {
          LApp.pages.add(_this);
          wx.navigateTo({
            url: '../outStorage',
          })
        }
  }
  //click relation Info
  // relationInfo:function(){
  //   let _this=this;
  //   LApp._get({
  //     url: "nbapi/fleedtool/getinfo/formcode",
  //     data: { formType: 'CK', enterpriseId: LApp.globalData.userInfo.EnterpriseId},
  //     success: function (res) {
  //       _this.data.outInfo.FormCode = res;
  //       //页面传值并跳转
  //       if (_this.data.outInfo) {
  //         LApp.pages.add(_this);
  //         wx.navigateTo({
  //           url: '../outStorage',
  //         })
  //       }
  //     }
  //   })
   
  // }
})